<?php
/**
 * spsNewsletter config
 * 
 * @author Satyan Shah <joomlaDesign@modernbridge.com>
 * @link http://www.modernbridge.com
 * @license GNU/GPL
 */
 

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport('joomla.application.component.model');

class spsNewslettersModelspsNewsletterConfig extends JModel
{
	/**
	 * Constructor that retrieves the ID from the request
	 *
	 * @access	public
	 * @return	void
	 */
	function __construct()
	{
		parent::__construct();
	}
	
	function store()	{
		//TODO: There has to be a better way to update component params via the Joomla API. 

		//define the parameter seperator
		$ps="\n";
		$fromName = JRequest::getVar( 'fromName','','post','string');
		$fromEmail = JRequest::getVar( 'fromEmail','','post','string');
		$testEmailAddress = JRequest::getVar( 'testEmailAddress','','post','string');
    
		// build the parameter string
		$componentParamString=
		"fromName=".$fromName.$ps
		."fromEmail=".$fromEmail.$ps
		."testEmailAddress=".$testEmailAddress;
    
		// establish DB connection
		$db=& $this->getDBO();
		// author query. 
		$query = "UPDATE #__components SET params = '$componentParamString' WHERE #__components.option = 'com_spsnewsletter' LIMIT 1" ;
		// execute query and test result 
		$db->setQuery($query);
		$action = $db->loadResult();
		if ($db->getErrorNum()) 
		{
			JError::raiseError( 500, $db->stderr() );
			return false; // Exit Point, Task Failed
		} 
		
		return true; // Exit Point. Task Succeeded
	}

}
?>
